<?php
/**
 * 优惠卷操作Action
 * @author tangbl
 *
 */
class CouponAction extends CommonAction{
	
	public function index() {				
		$user = getMember();
		if(IS_POST){
			$map['userid']   = $user['id'];
			$map['realname'] = $this->_param("realname");
			$map['mobile']   = $this->_param("mobile");
			$map['yhjid']    = $this->_param("yhjid");
			$json = sendRest("Coupon/get", $map);
			
			$this->assign("jumpUrl",U('/Member/yhj_list'));
			$this->success(L('yhj_form_ele_yhjsuccess'));
		}else{
			$id = $this->_param("id");
			
			$map['format'] = 1;
			$map['id']     = $id;
			$json = sendRest("Coupon/uselist",$map);
			
			$this->assign("Yhj",$json['data']);
			$this->display();
		}
	}
	
	public function detail(){
		
		$id = $this->_param("id","intval",0);
		
		$map['id']     = $id;
		$map['format'] = 1;
		$json = sendRest("Coupon/detail",$map);
		
		$this->assign("detail",$json['data']);
		$this->display();
	}
	
	public function addyhjlog() {
		
		$yhjlog = D("Actyhjlog");
		$cardid  = $this->_param("activityid");
		$mobile  = $this->_param("mobile");
		$m['activityid'] = $cardid;
		$m['mobile']     = $mobile;
		$m['status']     = 2;
		
		$rowlog = $yhjlog->where($m)->find();
		if($rowlog['id']){
			$this->error(L('yhj_form_ele_phone'),U('/Member/yhj'));
		}
		
		if($yhjlog->create()){
			$data['sn']         = $this->_post("sn");
			$data['solevar']    = create_id();
			$data['activityid'] = $cardid;
			$data['realname']   = $this->_param("realname");
			$data['username']   = $mobile;
			$data['mobile']     = $mobile;
			$data['addtime']    = time();
			$flag 				= $yhjlog->add($data);
			
			if($flag){
				$this->assign("jumpUrl",U('/Member/yhj'));
				$this->success(L('yhj_form_ele_yhjsuccess'));
			}else{
				$this->error(L('yhj_form_ele_yhjfail'));
			}
		}else{
			$this->error($yhjlog->getError());
		}
	}
}
?>